/**
 * 描述: 初始化路由信息，自定义全局异常处理
 * 作者: Jack Chen
 * 日期: 2020-06-19
 */
import express from "express";
import constant from "../utils/constant.js";
import { getMainUrl } from "../modules/main.js";
import { getCategoryData, getOeData } from "../modules/main-img.js";

const { CODE_SUCCESS } = constant;
const router = express.Router(); // 注册路由

router.get("/querySn", async (req, res, next) => {
  const r = await getMainUrl(req.query.code);
  res.json({
    code: CODE_SUCCESS,
    msg: true,
    data: r,
  });
});

router.get("/category/data", async (req, res, next) => {
  const key = decodeURIComponent(req.query.key);
  const r = await getCategoryData(key);
  res.json({
    code: CODE_SUCCESS,
    msg: true,
    data: r,
  });
});

router.get("/query/oe", async (req, res, next) => {
  const key = decodeURIComponent(req.query.key);
  const r = await getOeData(key);
  res.json({
    code: CODE_SUCCESS,
    msg: true,
    data: r,
  });
});

router.use("/api", router); // 注入任务路由模块

export default router;
